from system.object import Object

class Agent(Object):
    def __init__(self, parent, type = None, name = None):
        Object.__init__(self,parent,type,name)
        
        self.defaultVar("gfx","agent")
        self.defaultVar("renderOp2d","sceneNode")
        
        self.defaultVar("scale",(50,50))
        self.defaultVar("pos",(0,0))
        self.defaultVar("rot",0)
        
        self.defaultVar("speed",10)
        self.defaultVar("turnSpeed",1)
        
        self.gfx = self.addChild(self.getVar("gfx"),"gfx")
        self.controller = self.addChild("calm.loopController")
        
        points = self.flattenVars("points")
        if points:
            sumx = sumy = count = 0
            for px, py in points:
                sumx += px
                sumy += py
                count += 1
                
            cx = sumx / float(count)
            cy = sumy / float(count)
            
        else:
            cx = cy = 0.5
            
        self.gfx.setVar("static",True)
        self.gfx.setVar("pos",(-cx,-cy))
